package com.victor.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.victor.dao.TimerDao;
import com.victor.entity.User;
import com.victor.entity.finefood.Food;
import com.victor.entity.happy.Happy;
import com.victor.entity.hotel.Hotel;
import com.victor.service.TimerService;

@Service
public class TimerServiceImpl implements TimerService {

	@Autowired
	private TimerDao dao;

	// 用户冻结更新
	@Override
	public void updateFrozenUsers() {
		// 查询需要解冻用户(排除冻结状态为0 [终身冻结]的) (解冻时间在当前时间之前的)
		List<User> frozenUsers = dao.getFrozenUser();
		if (frozenUsers != null && frozenUsers.size() > 0) {
			// 对用户进行解冻
			for (User user : frozenUsers) {
				dao.updateFrozenUsers(user.getId());
			}
		}

	}

	// 每分钟检查一遍冻结的宾馆商家
	@Override
	public void updateFrozenHotel() {
		// 查询需要解冻宾馆用户(排除冻结状态为0 [终身冻结]的) (解冻时间在当前时间之前的)
		List<Hotel> frozenHotels = dao.getFrozenHotel();
		if (frozenHotels != null && frozenHotels.size() > 0) {
			// 对宾馆商家进行解冻
			for (Hotel hotel : frozenHotels) {
				dao.updateFrozenHotel(hotel.getH_id());
			}
		}
	}

	// 每分钟检查一遍冻结的美食商家
	@Override
	public void updateFrozenFinefood() {
		// 查询需要解冻美食商家(排除冻结状态为0 [终身冻结]的) (解冻时间在当前时间之前的)
		List<Food> frozenFoods = dao.getFrozenFood();
		if (frozenFoods != null && frozenFoods.size() > 0) {
			// 对美食商家进行解冻
			for (Food food : frozenFoods) {
				dao.updateFrozenFood(food.getF_id());
			}
		}
	}

	// 每分钟检查一遍冻结的娱乐商家
	@Override
	public void updateFrozenHappy() {
		// 查询需要解冻娱乐商家(排除冻结状态为0 [终身冻结]的) (解冻时间在当前时间之前的)
		List<Happy> frozenHappys = dao.getFrozenHappy();
		if (frozenHappys != null && frozenHappys.size() > 0) {
			// 对娱乐商家进行解冻
			for (Happy happy : frozenHappys) {
				dao.updateFrozenHappy(happy.getH_id());
			}
		}
	}

}
